package classdemo;

import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @DESCRIPATION
 * @AUTHOR 戴超
 * @DATE 2018/6/19
 **/
public class InetAddressTest {
    public static void main(String[] args) throws IOException {
        InetAddress locAdd = InetAddress.getLocalHost(); //  得到本地InetAddress 对象
        InetAddress remAdd = null;  //  声明InetAddress 对象
        System.out.println(locAdd.getCanonicalHostName());
        System.out.println(locAdd.getHostName());
        System.out.println(locAdd.getHostAddress());

        remAdd = InetAddress.getByName("www.yuanrenhome.com");
        System.out.println(" 本机IP 地址："
                + locAdd.getHostAddress());//  得到本地IP 地址
        System.out.println("yuanrenhome 的IP 地址："
                + remAdd.getHostAddress());//  得到远程IP 地址
        System.out.println(" 本机是否可达：" + locAdd.isReachable(5000));
    }
}
